// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Creates groups in zones around target
// -----------------------------------------------

#define LOCATION_TYPES ["FlatArea","FlatAreaCity","FlatAreaCitySmall","Airport","NameCityCapital","NameCity","NameVillage","Hill","Mount"]

private ["_location", "_weight", "_position", "_locations", "_differance", "_temp", "_count", "_marker"];

_location = _this select 0;
_weight   = _this select 1;

_position = position _location;

if (wckindofserver == 3) then {wcambiantdistance = 2500};

// Create enemies around target
_locations = nearestLocations [_position, LOCATION_TYPES, wcambiantdistance];
{
	if (_position distance (position _x) < 600) then {
		_locations = _locations - [_x];
	};
} forEach _locations;

if (wckindofserver != 3) then {
	wcambiantdistance = wcambiantdistance + 200;
};

_locations = (_locations) call WC_fnc_arrayShuffle;

if (count _locations > wclevelmaxoutofcity) then {
	_differance = count _locations - wclevelmaxoutofcity;
	for "_i" from 0 to (_differance - 1) do {
		_temp = random (count _locations - 1);
		_locations set [_temp, objNull];
		_locations = _locations - [objNull];
	};
};

_count = 0;

{
	if (wcwithcomposition == 1) then {
		[_x] spawn WC_fnc_createcomposition;
	};

	_marker = [format ["ambiant%1", wcambiantindex], position _x, (wcdistance * 2), "ColorRed", "ELLIPSE", "FDIAGONAL", "EMPTY", 0, "", WC_MarkerAlpha] call WC_fnc_createmarkerlocal;
	wcambiantmarker set [count wcambiantmarker, _marker];
	wcambiantindex = wcambiantindex + 1;
	_count = _count + 1;

	if (random 1 > 0.7) then {
		[_marker, wcvehicleslistE call WC_fnc_selectRandom, true, _weight] spawn WC_fnc_creategroup;
	} else {
		[_marker, wcfactions call WC_fnc_selectRandom, false] spawn WC_fnc_creategroup;
	};

	sleep 1;
} forEach _locations;

["INFO", format ["Created %1 ambiant patrol groups", _count]] call WC_fnc_log;
